package com.zz.service;

import com.zz.domain.ZipArchive;
import com.zz.mapper.ZipArchiveMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ZipArchiveService {
    @Autowired
    private ZipArchiveMapper zipArchiveMapper;

    public void saveArchive(ZipArchive archive) {
        zipArchiveMapper.insert(archive);
    }

    public void updateArchive(ZipArchive archive) {
        zipArchiveMapper.update(archive);
    }

    public List<ZipArchive> getAllArchives() {
        return zipArchiveMapper.selectAll();
    }

    public List<ZipArchive> getArchivesByExamId(String examId) {
        return zipArchiveMapper.selectByExamId(examId);
    }

    public List<ZipArchive> getArchivesByStatus(String status) {
        return zipArchiveMapper.selectByStatus(status);
    }

    public List<ZipArchive> getLatestArchives(int limit) {
        return zipArchiveMapper.selectLatest(limit);
    }

    public String getUploadStats() {
        long total = getAllArchives().size();
        long success = getArchivesByStatus("success").size();
        long failed = getArchivesByStatus("failed").size();
        long pending = getArchivesByStatus("pending").size();

        return String.format("Total: %d, Success: %d, Failed: %d, Pending: %d",
                total, success, failed, pending);
    }
}